
       ld      bc,HandlerSize           ; Number of bytes to copy
       ld      de,DCB11                 ; Where to copy code to
       ld      hl,ErrorHandler          ; Where to copy code from
       ldir                             ; Copy the code

       ld      bc,3                     ; Number of bytes to copy
       ld      de,READBLOCK             ; Vector to change
       ld      hl,NewReadBlockVector    ; New vector
       ldir                             ; Copy it

       call    READKEYBOARD

       call    ClearScreen

       ld      bc,0                     ; Setup to load block 0 of the device
       ld      de,0
       ld      hl,0c800h                ; where to load block 0
       ld      a,FALSE                  ; No indicator
       call    LoadBlock
       ld      a,(BOOTDRIVE)            ; Get the boot device
       ld      b,a                      ; Need to setup to run the block we loaded

       jp      0c800h                   ; Go run it


; ErrorHandler
;
; This code will be executed when a call is made to READBLOCK
;
; 1. We wedge this code into the EOS DCB's starting with DCB 11
;    Note - each DCB is 21 bytes long and the first byte tells 
;    the 6801 what to do with the DCB - since we don't want the 
;    6801 touching it we put a NOP (0) in the first byte of 
;    each DCB we use
; 2. We change the jump vector at 0FCF3h to be a JP to our code
; 3. We then call the original READBLOCK and when it returns we look
;    for an error. If no error we return to the original calling 
;    program
; 4. If there is an error we save the registers we use and then 
;    sound a BUZZ through the speaker and wait for the user
;    to press a key after unmounting and remounting the VDD
; 5. We then restart the wedge, calling READBLOCK

ErrorHandler: .module ErrorHandler
       nop                             ; First byte of DCB 11 tells 6801 to ignore this DCB
       call    0F17Bh                  ; Do the actual read block
       ret     z                       ; No errors so return to calling program
       push    af                      ; Save all the registers we touch
       push    bc
       ld      a,080h                  ; Error so sound the alarm
       out     (SOUNDPORT),a
       ld      a,077h
       out     (SOUNDPORT),a
       ld      a,090h
       out     (SOUNDPORT),a
_pad12:
       .fill   21 - (_pad12 - ErrorHandler),0  ; Fill with NOP's
       nop                             ; First byte of DCB 12 tells 6801 to ignore this DCB
       call    READKEYBOARD            ; Go wait for a key to be pressed
       call    SOUNDOFF                ; Turn off the sounds
       pop     bc                      ; Get the registers back we touched
       pop     af
       jr      ErrorHandler            ; Go do it again
ErrorHandlerEnd:

HandlerSize:   .equ ErrorHandlerEnd - ErrorHandler

NewReadBlockVector:
       jp      DCB11
